package com.itcrowd.ittao.view;

import com.itcrowd.ittao.R;
import com.itcrowd.ittao.utils.ImageManager;

import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class MainActivity extends FragmentActivity implements OnCheckedChangeListener {

	private static final String SHOPPINGLIST_TAG = "shoppinglist";
	private static final String MINE_TAG = "mine";
	private static final String SETTING_TAG = "setting";

	private ShoppingListFragment mShoppingListFragment;
	private MineFragment mMineFragment;
	private SettingFragment mSettingFragment;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		int title = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
		TextView titleView = (TextView) findViewById(title);
		titleView.setTextColor(Color.WHITE);
		
		RadioGroup tabs = (RadioGroup) findViewById(R.id.tabs);
		tabs.setOnCheckedChangeListener(this);
		tabs.check(R.id.shoppinglist);
		
		ImageManager.init(this);
	}
	
	@Override
	public void onCheckedChanged(RadioGroup arg0, int id) {
		FragmentManager fm = getSupportFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		switch(id) {
		case R.id.shoppinglist:
			if(mShoppingListFragment == null) {
				mShoppingListFragment = new ShoppingListFragment();
			}
			ft.replace(R.id.tabcontent, mShoppingListFragment, SHOPPINGLIST_TAG);
			break;
		case R.id.mine:
			if(mMineFragment == null) {
				mMineFragment = new MineFragment();
				
			}
			ft.replace(R.id.tabcontent, mMineFragment, MINE_TAG);
			break;
		case R.id.setting:
			if(mSettingFragment == null) {
				mSettingFragment = new SettingFragment();
				
			}
			ft.replace(R.id.tabcontent, mSettingFragment, SETTING_TAG);
			break;
		}
			
		ft.commit();
		
	}

}
